﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace Smile.Xaml.Converter
{
    public class StreamToImageConverter : IValueConverter
    {
        // @Public
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                Stream imageStream = (Stream)value;
                var image = new BitmapImage();
                image.SetSource(imageStream);
                return image;
            }
            catch
            {
                return new BitmapImage();
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return new NotImplementedException("UriToImageConverter");
        }
    }
}
